#include <stdio.h>
#include <stdlib.h>
#include <sys/mman.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <sys/wait.h>
int var = 100;
int main(){
    int len = 100;
    int *p = mmap(NULL,len,PROT_READ|PROT_WRITE,MAP_SHARED|MAP_ANON,-1,0);
    if (p == MAP_FAILED){
        perror("mmap error");
        exit(1);
    }
    int pid = fork();
    if (pid == 0){
        *p = 1000;
        var = 200;
        printf("child , *p = %d, var = %d\n",*p,var);
    }else {
        sleep(1);
        printf("parent,  *p = %d, var = %d\n",*p,var);
        wait(NULL);
    }


    int ret = munmap(p,len);
    if (ret == -1){
        perror("munmap error");
        exit(0);
    }
    return 0;
}